@extends('layouts.layouts')
@section('title')
    <title>视频页面</title>
@endsection
@section('content')
<link rel="stylesheet" href="/lib/layer/theme/default/layer.css"/>
    <script type="text/javascript" src="/lib/layer/layer.js"></script>
<div class="content">
        <div class="header">       
            <h1 class="page-title">课程顾问申请列表</h1>
             <ul class="breadcrumb"></ul>
        </div>
        <div class="main-content">

        <div class="btn-toolbar list-toolbar">
                <form class="form-inline col-sm-4" action="" method="get">
					
                <!-- <a href="/dis/coursea">
                  <button type="button" class="btn btn-primary">
                    <i class="glyphicon glyphicon-home"></i> 添加课程</button>
                </a> -->
                <div class="form-group">
                    <input type="text" class="form-control" name="title" placeholder="客户昵称" value="">
                </div>
                <button type="submit" class="btn btn-default">筛选</button>
                </form>
                <ul class="nav nav-pills">
                    <li role="presentation" class="{{$code ==0 ? 'active' : ''}}"><a href="?code=0">正在审核</a></li>
                    <li role="presentation" class="{{$code ==1 ? 'active' : ''}}"><a href="?code=1">已通过</a></li>
                    <li role="presentation" class="{{$code ==2 ? 'active' : ''}}"><a href="?code=2">已拒绝</a></li>
                </ul>
          </div>
 <div class="panel panel-default">

<div class="panel-heading no-collapse">视频列表<!-- <span class="label label-warning">+10</span> --></div>
<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>序号</th>
      <th>姓名--用户id</th>
      <th>手机号</th>
      <th>微信二维码</th>
      <th>身份证号</th>
      <th>关联导师手机号</th>
      <th>备注信息</th>
      <th>状态</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
<div>
@foreach($list as $v)
		<tr id="course_{{$v->id}}">
				  <td>{{$v->id}}</td>
				  <td>{{$v->name}}--{{$v->user_id}}</td>
				  <td>{{$v->mobile}}</td>
          <td><img class="pimg" height='80' src="{{env('IMG_URL')}}{{$v->wx_img}}" /></td>
				  <td>{{$v->id_card}}</td>
          <td>{{$v->teacher_mobile}}</td>
          <td>{{$v->remark ? $v->remark : "---"}}</td>
          <td>
            @if($v->code==0)
            正在审核
            @elseif($v->code==1)
            已通过
            @else
            已拒绝
            @endif
          </td>
				  <td width="20%">
            @if($code==0)
					  <a href="javascript:;" data-id="{{$v->id}}" onclick="can(this)"><i class="fa fa-pencil"></i>通过</a>&nbsp;|
					  <a href="javascript:;" data-id="{{$v->id}}" onclick="refuse(this)"><i class="fa fa-trash-o"></i>拒绝</a>&nbsp;|
            @endif
            @if($code==2)
             <a href="javascript:;" data-id="{{$v->id}}" onclick="can(this)"><i class="fa fa-pencil"></i>通过</a>&nbsp;|
            @endif
            <a href="javascript:;" data-id="{{$v->id}}" onclick="tMobile(this)"><i class="fa fa-pencil"></i>关联老师</a>&nbsp;
				  </td>
		</tr>
@endforeach
</div>

  </tbody>
</table>
</div>

  <ul class="pagination">
  {{$list->appends(['title'=>$title])->render()}}
  </ul>
</div>


</div>
    <script type="text/javascript">
       
    </script>

    <script src="lib/bootstrap/js/bootstrap.js"></script>
    <script>
        $(".link").click(function(){
           // console.log($(this).next());
            $(this).next().toggleClass('submenu1');
        })

        //执行通过方法
        function can(obj){
            var id = $(obj).attr('data-id');
            var _token = '{{csrf_token()}}';
            var code   = 1;
            
            layer.prompt({title: '确认通过么？请填写备注', formType: 2}, function(text,index){
              layer.close(index);
              //layer.msg('您最后写下了：'+text);
              var data = {id:id, code:code, remark:text ,_token:_token};
              //return;
                $.ajax({
                    url:'/dis/form/code',
                    data:data,
                    type:'POST',
                    dataType: 'json',
                    success:function(res){
                        console.log(res);
                        if(res.code == 1){
                            $("#course_"+id).remove();
                        }else{
                             layer.alert(res.msg);
                        }
                    }
                });
                layer.close(index);
                return true;
            }, function(index){
                layer.close(index);
            });
        }

        //执行拒绝方法
        function refuse(obj){
            var id = $(obj).attr('data-id');
            var _token = '{{csrf_token()}}';
            var code   = 2;
            layer.prompt({title: '确认拒绝么？请填写备注', formType: 2}, function(text,index){
              layer.close(index);
              //layer.msg('您最后写下了：'+text);
              var data = {id:id, code:code, remark:text ,_token:_token};
                $.ajax({
                    url:'/dis/form/code',
                    data:data,
                    type:'POST',
                    dataType: 'json',
                    success:function(res){
                        console.log(res);
                        if(res.code == 1){
                            $("#course_"+id).remove();
                        }else{
                             layer.alert(res.msg);
                        }
                    }
                });
                layer.close(index);
                return true;
            }, function(index){
                layer.close(index);
            });
        }

        //关联老师
        function tMobile(obj){
            var id = $(obj).attr('data-id');
            var _token = '{{csrf_token()}}';
            layer.prompt({title: '请填写关联老师的手机号', formType: 2}, function(text,index){
              layer.close(index);
              
              var data = {id:id, mobile:text ,_token:_token};
                $.ajax({
                    url:'/dis/form/mobile',
                    data:data,
                    type:'POST',
                    dataType: 'json',
                    success:function(res){
                        console.log(res);
                        if(res.code == 1){
                            layer.alert(res.msg);
                            $("#course_"+id).children().eq(5).text(text);
                        }else{
                             layer.alert(res.msg);
                        }
                    }
                });
                layer.close(index);
                return true;
            }, function(index){
                layer.close(index);
            });
        }

        function articleDelete(obj){
            var id = $(obj).attr('data-id');
            var _token = '{{csrf_token()}}';
            var data = {id:id,_token:_token};
            layer.confirm('确定删除吗？', {
                btn: ['是', '否'],
            }, function(index){
                $.ajax({
                    url:'/dis/coursed',
                    data:data,
                    type:'POST',
                    dataType: 'json',
                    success:function(res){
                        layer.alert(res.message);
                        if(res.code == 0){
                            $("#course_"+id).remove();
                        }

                    }
                });
                layer.close(index);
                return true;
            }, function(index){
                layer.close(index);
            });

        }
    </script>

@endsection
